#include "AudioFile.h"

using namespace LibMusic ;

int AudioFile::m_nbInstances(0) ;
FMOD::System* AudioFile::m_FmodSyst(NULL) ;

// Constructor(string)
AudioFile::AudioFile(const std::string & _Path)
	: m_Path(_Path)
	, m_Sound(NULL)
{
	if(m_nbInstances == 0)
	{
		FMOD_RESULT res1 = FMOD::System_Create(&m_FmodSyst) ;
		FMOD_RESULT res2 = m_FmodSyst->init(100, FMOD_INIT_NORMAL, NULL) ;
	}
	m_nbInstances++ ;
}

// Destructor
AudioFile::~AudioFile()
{
	m_nbInstances-- ;
	if (m_nbInstances == 0)		m_FmodSyst->release() ;
	// Pas besoin de deleter m_Sound, FMOD s'en occupe.
}

// Play
 void AudioFile::Play()
 {
	FMOD_RESULT res1 = m_FmodSyst->createStream(m_Path.c_str(), FMOD_DEFAULT, 0, &m_Sound) ;
	FMOD_RESULT res2 = m_FmodSyst->playSound(FMOD_CHANNEL_FREE, m_Sound, false, 0) ;
 }

